package com.github.ykrank.androidtools.service

import com.github.ykrank.androidtools.BuildConfig
import com.google.gson.Gson
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class RestApiHelper {


    companion object {
        fun create(): ApiService {
            val okClient = OkHttpClient.Builder()
                    .connectTimeout(2000L, TimeUnit.MILLISECONDS)
                    .retryOnConnectionFailure(true)
//                .addNetworkInterceptor {
//                    it.proceed(it.request().newBuilder()
//                            .addHeader("appdevice", "android")
//                            .addHeader("apptoken", TokenManager.token())
//                            .addHeader("plat", BuildConfig.ChannelId).build())
//                }
                    .build()
            return Retrofit.Builder()
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(GsonConverterFactory.create(Gson()))
                    .client(okClient)
                    .baseUrl(BuildConfig.BASE_URL)
                    .build().create(ApiService::class.java)

        }
    }

}